<?php
$loader->requireOnce('includes/EwhValuatePrice/IValuatePriceMethod.class.php');
$loader->requireOnce('includes/EwhValuatePrice/ValuatedPricesResult.class.php');
/**
 * pro for valuated engine. This class process valuating prices by imported Price
 * @package modules.dept_pharmacy.includes.EwhValuatePrice
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class ValuatePricesByImportedPrice implements IValuatePriceMethod {
	
    private $logger ;
    
    function __construct() {
        
        $this->logger = LoggerManager::getLogger('modules.dept_pharmacy.includes.EwhValuatePrice.ValuatePricesByImportedPrice');
        
    }
	public function valuatePrices($metaData=array(), $valuatingIdList=array()) {
	    $this->logger->info('Start valuatePrices ');
	    $resultArr = array();
	    
	    foreach ($valuatingIdList as $item) {
	        //get imported price
	        $phaEwhExticketDetailObj = Celini::newOrdo('PhaEwhImticketDetail');
	        $phaEwhExticketDetailObj->setup($item);
	        //allow to update valuated item
	        /*if ($phaEwhExticketDetailObj->get('valuated') ==0) {
	         * 
	         */
	            $result = new ValuatedPricesResult();
	            $result->setImticketDetailId($item);	            
	            $result->setRefImticketDetailId($item);
	            $servicePrice = $phaEwhExticketDetailObj->get('im_unit_price');
	            if ($metaData['enum_rate_type'] == EnumerationConstant::PHA_VALUATE_RATE_TYPE_PERCENT_KEY) {
	                $servicePrice = $phaEwhExticketDetailObj->get('im_unit_price')
	                 + (($metaData['service_rate'] * $phaEwhExticketDetailObj->get('im_unit_price'))/100);
	            } else if ($metaData['enum_rate_type'] == EnumerationConstant::PHA_VALUATE_RATE_TYPE_VND_KEY) {
	                $servicePrice = $phaEwhExticketDetailObj->get('im_unit_price')
                     + $metaData['service_rate'] ;
	            }
	            
	           $insurrancePrice = $phaEwhExticketDetailObj->get('im_unit_price');
                if ($metaData['enum_rate_type'] == EnumerationConstant::PHA_VALUATE_RATE_TYPE_PERCENT_KEY) {
                    $insurrancePrice = $phaEwhExticketDetailObj->get('im_unit_price')
                     + (($metaData['insurance_rate'] * $phaEwhExticketDetailObj->get('im_unit_price')/100));
                } else if ($metaData['enum_rate_type'] == EnumerationConstant::PHA_VALUATE_RATE_TYPE_VND_KEY) {
                    $insurrancePrice = $phaEwhExticketDetailObj->get('im_unit_price')
                     + $metaData['insurance_rate'] ;
                }
	            
	            $result->setServicePrice($servicePrice);
	            $result->setInsurancePrice($insurrancePrice);
	            $result->setRefImticketDetailId($item);
	            $resultArr[] = $result;
	        //}        
	        //calculate
	        //add result into result array
	    }    
	    
	    $this->logger->info('finish valuatePrices ');   
	    return $resultArr; 
	}
	
}
?>